<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category BaseService.php
 * @Depiction
 * @Author hwy <429208948@qq.com>
 * @Date 2022/3/3  18:13
 * +--------------------------------------------------------+
 */

namespace App\Services;

class BaseService
{
    const STATUS_ON = 1;
    const STATUS_OFF = 2;
    protected $perPage = 10;

    public function commonSetStatusValue($param)
    {
        $status = empty($param) ? self::STATUS_OFF : $param;
        return $status;
    }

    /**
     * @param $data
     * @return array
     * @Depiction
     * @Author hwy <429208948@qq.com>
     * @Date 2022/4/7  13:56
     */
    public function initPaginateData($data)
    {
        $data                = $data->toArray();
        $res                 = [];
        $res['data']         = $data['data'] ?? [];
        $res['current_page'] = $data['current_page'] ?? 0;
        $res['last_page']    = $data['last_page'] ?? 0;
        $res['per_page']     = $data['per_page'] ?? 10;
        $res['total']        = $data['total'] ?? 0;

        return $res;

    }
}
